#include "backtracking.h"

class Residues {
protected:
  int cacheSize; // The length of the cache

  /* This cache is for value a of D_i wrt c_{ij}
   * value starts from 1 to d. 
   * variables: numbered from 0 to n-1
   */
  int vari, varj, va; 
  static BT *csp; 
 
public:
  /* Obtain the csp problem instance and the associated 
   * problem solving procedures and data.
   */
  static void setCSP(BT *csp1) { csp = csp1; }
  /* Initialize the cache size, value a and variables i and j 
   * Allocation of the cache for residues is done in the
   * derived classes of Residues. 
   */
  virtual void initialize(int k, int i, int j, int a) = 0;
  virtual bool findSupport() = 0;
  /* Add to the cache the support found from outside cache*/
  virtual void add(int b) = 0;
  /* Add the first residue to the cache. This is called before findSupport
   * and add() and called only once in solving one problem instance.
   */
  virtual void initAdd(int b) = 0;
  /* Check if the value b is in the current domain of varj */
  bool isValid(int b) { return csp->isValid(varj, b)};
  Residues(){};
  ~Residues(){};
  void set(int k, int i1, int j1, int a1){
    cacheSize = k;
    vari = i1; 
    varj = j1; 
    va = a1;
  }
};
// define the static member
BT *Residues::csp;
